package com.pxmeta.app.controller.game;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.google.common.collect.Maps;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.common.utils.SecurityUtils;
import com.pxmeta.matching.entity.dto.CreateSoundCardDTO;
import com.pxmeta.matching.entity.dto.DislikeSoundCardDTO;
import com.pxmeta.matching.entity.dto.LikeSoundCardDTO;
import com.pxmeta.matching.entity.vo.LikeSoundVO;
import com.pxmeta.user.entity.User;
import com.pxmeta.user.entity.dto.UserDTO;
import com.pxmeta.user.service.IUserMatchService;
import com.pxmeta.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.directory.shared.kerberos.codec.apRep.actions.ApRepInit;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * 声音匹配前端控制器
 */
@RestController
@Api(value = "声音匹配",tags = "声音匹配")
@RequiredArgsConstructor
public class SoundMatchingController {

    private final IUserService userService;
    private final IUserMatchService userMatchService;


    @ApiOperation("创建声音卡片")
    @PostMapping("/createSoundCard")
    public AjaxResult createSoundCard(@RequestBody CreateSoundCardDTO dto){
        Long userId = SecurityUtils.getUserId();
        userService.createVoiceCard(userId,dto.getVoiceUrl(), dto.getImgUrl());
        return AjaxResult.success();
    }


    @ApiOperation("获取声音卡片列表")
    @GetMapping("/getMatchList")
    public AjaxResult getList(){
        Long userId = SecurityUtils.getUserId();
        List<UserDTO> users = userService.getVoiceMatchList(userId);
        return AjaxResult.success(users);
    }


    @ApiOperation("喜欢")
    @PostMapping("/like")
    @SaCheckLogin
    public AjaxResult like(@RequestBody LikeSoundCardDTO dto){
        Long userId = SecurityUtils.getUserId();
        Long targetUserId = dto.getTargetUserId();
        boolean targetIsLike = userMatchService.like(userId, targetUserId);
        LikeSoundVO vo = new LikeSoundVO();
        vo.setTargetIsLike(targetIsLike);
        return AjaxResult.success(vo);
    }

    @ApiOperation("不喜欢")
    @PostMapping("/dislike")
    @SaCheckLogin
    public AjaxResult dislike(@RequestBody DislikeSoundCardDTO dto){
        Long userId = SecurityUtils.getUserId();
        Long targetUserId = dto.getTargetUserId();
        userMatchService.dislike(userId, targetUserId);
        return AjaxResult.success();
    }

    @ApiOperation("获取今日匹配次数")
    @GetMapping("/getTodayMatchCount")
    @SaCheckLogin
    public AjaxResult getTodayMatchCount(){
        Long userId = SecurityUtils.getUserId();
        Integer count = userMatchService.getTodayMatchCount(userId);
        HashMap<String, Object> map = Maps.newHashMap();
        map.put("count",20-count);
        return AjaxResult.success(map);
    }

}
